/*
 * MainTable.java
 *
 * Created on 2009年2月13日, 下午3:35
 */

package main.view;
import java.net.*;
import main.model.UserID_Model;
import main.model.ButtonModel;
import main.ucm.*;
import verify.view.DisplayInfo;
/**
 *
 * @author  I'm kevin
 */
public class MainTable extends javax.swing.JFrame {
    private DisplayInfo infoPanel;
    private ButtonModel button;
    private static MainTable local;
    private Socket socket;
    /** Creates new form MainTable */
    public MainTable() {
        this.setSize(800,600);
        initComponents();
        this.setLocationRelativeTo(null);
        this.userID_TF.setVisible(true);
        local=this;
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        Layer = new javax.swing.JLayeredPane();
        userID_TF = new javax.swing.JTextField();
        backGround_La = new javax.swing.JLabel();
        MenuBar = new javax.swing.JMenuBar();
        FileMenu = new javax.swing.JMenu();
        ExitItem = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("EOSPAN SYSTEM");
        setResizable(false);

        userID_TF.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                userID_TFActionPerformed(evt);
            }
        });
        userID_TF.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                userID_TFKeyPressed(evt);
            }
        });
        userID_TF.setBounds(40, 20, 170, -1);
        Layer.add(userID_TF, javax.swing.JLayeredPane.DEFAULT_LAYER);

        backGround_La.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/MainBG.jpg"))); // NOI18N
        backGround_La.setBounds(0, 0, 800, 600);
        Layer.add(backGround_La, javax.swing.JLayeredPane.POPUP_LAYER);

        FileMenu.setText("File");

        ExitItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Q, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        ExitItem.setText("Exit");
        ExitItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ExitItemActionPerformed(evt);
            }
        });
        FileMenu.add(ExitItem);

        MenuBar.add(FileMenu);

        setJMenuBar(MenuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(Layer, javax.swing.GroupLayout.PREFERRED_SIZE, 800, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(Layer, javax.swing.GroupLayout.PREFERRED_SIZE, 600, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void ExitItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ExitItemActionPerformed
        UserExit ue = new UserExit();
    }//GEN-LAST:event_ExitItemActionPerformed

    private void userID_TFKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_userID_TFKeyPressed
        if(evt.getKeyCode()==13||evt.getKeyCode()==10){
            UserCardInput.getInstance(this).run();
            this.setVisible(false);
        }
    }//GEN-LAST:event_userID_TFKeyPressed

    private void userID_TFActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_userID_TFActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_userID_TFActionPerformed


    public static MainTable getInstance()
    {
        if(local==null)
        {
            local=new MainTable();
            local.setVisible(true);
        }
        else
        {
            local.userID_TF.setText("");
            local.setVisible(true);
        }
        return local;
    }

    public UserID_Model getIDModel(){
        UserID_Model um = new UserID_Model();
        um.setUserID(this.userID_TF.getText());
        return um;
    }

    public ButtonModel getButtonModel()
    {
        button=new ButtonModel();
        button.setCardID(userID_TF);

        return button;
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MainTable().setVisible(true);
            }
        });
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem ExitItem;
    private javax.swing.JMenu FileMenu;
    private javax.swing.JLayeredPane Layer;
    private javax.swing.JMenuBar MenuBar;
    private javax.swing.JLabel backGround_La;
    private javax.swing.JTextField userID_TF;
    // End of variables declaration//GEN-END:variables
    
}
